/*
import java.util.*;
 数据流中的中位数

public class Solution {
    //大根堆
    PriorityQueue<Integer> min = new PriorityQueue<>((o1, o2)->o2 - o1);

    //小根堆
    PriorityQueue<Integer> max = new PriorityQueue<>((o1, o2)->o1 - o2);
    public void Insert(Integer num) {
        min.offer(num);
        max.offer(min.poll());
        if (max.size() > min.size()) {
            min.offer(max.poll());
        }
    }

    public Double GetMedian() {
        //奇数个
        if (min.size() > max.size()) {
            return (double)min.peek();
        } else {
            return (double)(max.peek() + min.peek()) / 2;
        }

    }
}
import java.util.*;

public class Solution {
    ArrayList<Integer> list = new ArrayList<>();
    int count = 0;
    public void Insert(Integer num) {
        list.add(num);
        count++;
    }
    public Double GetMedian() {
        Collections.sort(list);
        return count%2==1 ?(double)list.get(count/2):
         (double)(list.get(count/2)+list.get((count/2-1)))/2;
    }
}

逆波兰表达式求值

class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> s = new Stack<>();
        for(int i = 0;i < tokens.length; i++) {
            String str = tokens[i];
            if(isNumber(str)) {
                s.push(Integer.parseInt(str));
            } else {
                int num1 =s.pop();
                int num2 =s.pop();
                switch(str) {
                    case "+" :
                        s.push(num2+num1);
                        break;
                    case "-" :
                        s.push(num2-num1);
                        break;
                    case "*" :
                        s.push(num2*num1);
                        break;
                    case "/" :
                        s.push(num2/num1);
                        break;
                    default :
                }
            }
        }
        return s.pop();
    }
    public boolean isNumber(String str) {
        return !(str.equals("+") || str.equals("-")||str.equals("*")||str.equals("/")) ;
    }
}

最长连续序列
class Solution {
    public int longestConsecutive(int[] nums) {
        if(nums.length == 0) {
            return 0;
        }
        Arrays.sort(nums);
        int count = 1,ret = 1;
        for(int i = 1;i<nums.length;i++) {
            if(nums[i] - nums[i-1] == 0 || nums[i] -nums[i-1] == 1) {
                if(nums[i] -nums[i-1] == 0) {
                    count--;
                }
                count++;
            } else {
                count = 1;
            }
            ret = Math.max(ret,count);
        }
        return ret;
    }
}

class Solution {
    public int longestConsecutive(int[] nums) {
        HashSet<Integer> hash = new HashSet<>();
        for(int i : nums) {
            hash.add(i);
        }
        int ret = 0,count;
        for(int x : hash) {
            if(!hash.contains(x-1)) {
                //此时为起点
                count = 0;
                while(hash.contains(x)) {
                    x++;
                    count++;
                }
                ret = Math.max(count,ret);
            }
        }
        return ret;
    }
}

​
 字母异位词分组

class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String,List<String>> hash = new HashMap<>();
        for(String str : strs) {
            char[] ch = str.toCharArray();
            Arrays.sort(ch);
            String s = new String(ch);
            if(!hash.containsKey(s)) {
                hash.put(s,new ArrayList<>());
            }
                hash.get(s).add(str);
        }
        return new ArrayList<>(hash.values());
    }
}
 */